import 'dart:convert';
import 'package:ichinesereader/models/book/Book.dart';
import 'package:ichinesereader/models/book/MaxScore.dart';
import 'package:ichinesereader/models/book/BookQuizQuestion.dart';

BookQuiz bookQuizFromJson(String str) => BookQuiz.fromJson(json.decode(str));

String bookQuizToJson(BookQuiz data) => json.encode(data.toJson());

class BookQuiz {
  BookQuiz({
    this.id,
    this.firstAttempt,
    this.currentMaxScore,
    this.questions,
    this.baseResourceUrl,
    this.enableAudio,
    this.book,
    this.simpName,
    this.tradName,
    this.simpDescription,
    this.tradDescription,
  });

  String? id;
  bool? firstAttempt;
  MaxScore? currentMaxScore;
  List<QuizQuestion>? questions;
  String? baseResourceUrl;
  bool? enableAudio;
  Book? book;
  String? simpName;
  String? tradName;
  String? simpDescription;
  String? tradDescription;

  factory BookQuiz.fromJson(Map<String, dynamic> json) => BookQuiz(
        id: json["id"],
        firstAttempt: json["firstAttempt"],
        currentMaxScore: json["currentMaxScore"] != null
            ? MaxScore.fromJson(json["currentMaxScore"])
            : null,
        questions: json["questions"] != null
            ? List<QuizQuestion>.from(
                json["questions"].map((x) => QuizQuestion.fromJson(x)))
            : null,
        baseResourceUrl: json["baseResourceUrl"],
        enableAudio: json["enableAudio"],
        book: json["book"] != null ? Book.fromJson(json["book"]) : null,
        simpName: json["simp_name"],
        tradName: json["trad_name"],
        simpDescription: json["simp_description"],
        tradDescription: json["trad_description"],
      );

  Map<String, dynamic> toJson() => {
        "id": id,
        "firstAttempt": firstAttempt,
        "currentMaxScore": currentMaxScore?.toJson(),
        "questions": questions != null
            ? List<dynamic>.from(questions!.map((x) => x.toJson()))
            : null,
        "baseResourceUrl": baseResourceUrl,
        "enableAudio": enableAudio,
        "book": book != null ? book?.toJson() : null,
        "simp_name": simpName,
        "trad_name": tradName,
        "simp_description": simpDescription,
        "trad_description": tradDescription,
      };
}
